var net = require('net');
var assert = require('assert');

var conn = null;
var port = 7001;

function connect(){
    conn = net.createConnection( port);

    conn.on('error', function(err){
        console.log(err.message);
    });
    conn.on('close', function(){
        // console.log("connect got closed");
    });
}

function disConnect() {
    conn.destroy();
}

describe('TCP server test', function() {
    beforeEach(function() {
        connect();
    });

    afterEach(function() {
        disConnect();
    });

    describe('tcp connect test', function () {
        it('connect to server', function () {
            assert(conn != null);
        });
    });

    describe('wrong request format test', function () {
        it('send wrong request format', function (done) {
            var request = "{\"version\":, \"method\": \"generateMnemonic\", \"params\": {\"length\":\"12\", \"language\":\"english\"}}";
            conn.write(request);
            conn.on('data', function (data) {
                var retObj = JSON.parse(data.toString());
                assert.equal(retObj.state, 10005);
                done();
            });
        });
    });

    describe('wrong request test', function () {
        var request = 	{"version":"1.0", "method": "generateMnemonic", "params": {"length":"12", "language":"english"}};
        it('send wrong version request', function (done) {
            request.version = "2.0";
            conn.write(JSON.stringify(request));
            conn.on('data', function (data) {
                var retObj = JSON.parse(data.toString());
                assert.equal(retObj.state, 10007);
                done();
            });
        });

        it('send wrong method request', function (done) {
            request.version = "1.0";
            request.method = "xxx";
            conn.write(JSON.stringify(request));
            conn.on('data', function (data) {
                var retObj = JSON.parse(data.toString());
                assert.equal(retObj.state, 10004);
                done();
            });
        });
    });

    describe('generate mnemonic, length 12 test', function () {
        var request = 	{"version":"1.0", "method": "generateMnemonic", "params": {"length":"12", "language":"english"}};
        it('generate wrong language mnemonic', function (done) {
            request.params.language = "xxxxx";
            conn.write(JSON.stringify(request));
            conn.on('data', function (data) {
                var retObj = JSON.parse(data.toString());
                assert.equal(retObj.state, 10002);
                done();
            });
        });

        it('generate english mnemonic', function (done) {
            request.params.language = "english";
            conn.write(JSON.stringify(request));
            conn.on('data', function (data) {
                var retObj = JSON.parse(data.toString());
                assert.equal(retObj.state, 10000);
                done();
            });
        });

        it('generate chinese mnemonic', function (done) {
            request.params.language = "chinese_simplified";
            conn.write(JSON.stringify(request));
            conn.on('data', function (data) {
                var retObj = JSON.parse(data.toString());
                assert.equal(retObj.state, 10000);
                done();
            });
        });
    });

    describe('generate address test', function () {
        var request = {
            "version": "1.0",
            "method": "generateAddress",
            "params": {"symbol": "btc", "language":"english", "mnemonic":"practice seek mad fold near shuffle wear toilet torch earn near response", "startIndex":"0", "amount":"1"}
        };

        it('generate BTc address', function (done) {
            request.params.symbol = "btc";
            conn.write(JSON.stringify(request));
            conn.on('data', function (data) {
                var retObj = JSON.parse(data.toString());
                assert.equal(retObj.data.bip32RootKey, "xprv9s21ZrQH143K3DqroJK1NM58Lpdy9JKW4xjMLJZWdx1gmKoUf825gbXuRz4418a4HtUbq6PbxL1j4QDbV3jtJq2UL3kFLjLhPDiv74AjS36");
                done();
            });
        });

        it('generate ETH address', function (done) {
            request.params.symbol = "ETH";
            conn.write(JSON.stringify(request));
            conn.on('data', function (data) {
                var retObj = JSON.parse(data.toString());
                assert.equal(retObj.data.bip32RootKey, "xprv9s21ZrQH143K3DqroJK1NM58Lpdy9JKW4xjMLJZWdx1gmKoUf825gbXuRz4418a4HtUbq6PbxL1j4QDbV3jtJq2UL3kFLjLhPDiv74AjS36");
                done();
            });
        });

        it('generate Ltc address', function (done) {
            request.params.symbol = "Ltc";
            conn.write(JSON.stringify(request));
            conn.on('data', function (data) {
                var retObj = JSON.parse(data.toString());
                assert.equal(retObj.data.bip32RootKey, "Ltpv71G8qDifUiNetCVSFCMdWmHsY66qEHzqUwkuHnwwdbbmn8aMXkne3SEZPkb4srDFD13suc387QiP3uLftAirwwPpHchRegPjBcLpAXeTvjP");
                done();
            });
        });
    });

    describe('sign BTC-T transaction test', function () {
        var input1 = {"txid":"9446e19cf038a030033cdc2c3835249c87b94e482d239f6f6dcdfcb455fcf911", "privateKey":"cUj2sYiSZYUwAD4MP5hFf6ceCVzR9n68yEW1CB2Kx5GQKTm8kcTk", "vout": 1};
        var input2 = {"txid":"e0d685a3d53a302462152096241d217500951fd2b90163f47517378d39973956", "privateKey":"cUj2sYiSZYUwAD4MP5hFf6ceCVzR9n68yEW1CB2Kx5GQKTm8kcTk", "vout": 1};
        var input3 = {"txid":"7b20586b8b3cc8c4c851e370cd77461f3aa54166c2cfd64d61b895f56e110067", "privateKey":"cRw1ubPGna7ovBaU9ZxvmvQaHq3gC396mg6MfgPotbLQ6h924r6c", "vout": 0};
        var input4 = {"txid":"ff735b05b592f176c822c8b4b2a2c7817dae109f72474cd2feed2bc0bb6f59f5", "privateKey":"cRw1ubPGna7ovBaU9ZxvmvQaHq3gC396mg6MfgPotbLQ6h924r6c", "vout": 0};

        var output1 = {"address":"2NAUGMDbJT85eadUieLeARrWamMHm2A7kUo", "amount":249800000};
        var output2 = {"address":"2NAUGMDbJT85eadUieLeARrWamMHm2A7kUo", "amount":49800000};

        var inputs = [];
        var outputs = [];
        var request = 	{"version":"1.0", "method": "signTx", "params": {"symbol": "BTC-T", "input":inputs, "output":outputs}};

        it(' 1 to 1 sign BTc transaction', function (done) {
            var inputs = [input1];
            var outputs = [output1];
            request.params.input = inputs;
            request.params.output = outputs;

            conn.write(JSON.stringify(request));
            conn.on('data', function (data) {
                var retObj = JSON.parse(data.toString());
                // console.log(retObj);
                assert.equal(retObj.data.rawTx, "010000000111f9fc55b4fccd6d6f9f232d484eb9879c2435382cdc3c0330a038f09ce14694010000006b483045022100e856c94feb35a511ab7b4c7397069e11346f87853f5a54445d0dbc79bfd2251c02200e355ef54f8510c4ddf44468fe453e4df7924383658537ee22058cdc47df53a40121023498cfb68e409c99565689d76987ab5035e8498ef816a50ef2dbb37f585dd14effffffff0140a5e30e0000000017a914bcf184420cd4c06186b1766d9d0dba5cddb1ec8a8700000000");
                done();
            });
        });

        it(' 1 to 2 sign BTc transaction', function (done) {
            var inputs = [input1];
            var outputs = [output1, output2];
            request.params.input = inputs;
            request.params.output = outputs;

            conn.write(JSON.stringify(request));
            conn.on('data', function (data) {
                var retObj = JSON.parse(data.toString());
                // console.log(retObj);
                assert.equal(retObj.data.rawTx, "010000000111f9fc55b4fccd6d6f9f232d484eb9879c2435382cdc3c0330a038f09ce14694010000006b483045022100fba6275bf7c03f1c39608c455e919473850c7c36401889fa837abd00430db93e02206fd9f2336f827f0e79d89af50437806c42b7ef25a1b9145e66e1ed914737c8050121023498cfb68e409c99565689d76987ab5035e8498ef816a50ef2dbb37f585dd14effffffff0240a5e30e0000000017a914bcf184420cd4c06186b1766d9d0dba5cddb1ec8a8740e3f7020000000017a914bcf184420cd4c06186b1766d9d0dba5cddb1ec8a8700000000");
                done();
            });
        });

        it(' 2 to 1 sign BTc transaction', function (done) {
            var inputs = [input1, input2];
            var outputs = [output1];
            request.params.input = inputs;
            request.params.output = outputs;

            conn.write(JSON.stringify(request));
            conn.on('data', function (data) {
                var retObj = JSON.parse(data.toString());
                // console.log(retObj);
                assert.equal(retObj.data.rawTx, "010000000211f9fc55b4fccd6d6f9f232d484eb9879c2435382cdc3c0330a038f09ce14694010000006a4730440220168df02ce2ee69311faed83d94474d5c3071144098ee6612625f3624ba8e381202207c4230ad64be6ca14386dea0bed468c6074a73c99f0a0cef87f32389c8bb30de0121023498cfb68e409c99565689d76987ab5035e8498ef816a50ef2dbb37f585dd14effffffff563997398d371775f46301b9d21f950075211d249620156224303ad5a385d6e0010000006b4830450221009160c6149f0050688be242ba3e24eb2c5b0eafbde679368338abcdb53b71769602207f810817247f4b196e226a34a660256e2dbf8066345cf98661019e42022a25320121023498cfb68e409c99565689d76987ab5035e8498ef816a50ef2dbb37f585dd14effffffff0140a5e30e0000000017a914bcf184420cd4c06186b1766d9d0dba5cddb1ec8a8700000000");
                done();
            });
        });

        it(' 2 to 2 sign BTc transaction', function (done) {
            var inputs = [input1, input2];
            var outputs = [output1, output2];
            request.params.input = inputs;
            request.params.output = outputs;

            conn.write(JSON.stringify(request));
            conn.on('data', function (data) {
                var retObj = JSON.parse(data.toString());
                // console.log(retObj);
                assert.equal(retObj.data.rawTx, "010000000211f9fc55b4fccd6d6f9f232d484eb9879c2435382cdc3c0330a038f09ce14694010000006a47304402204a2984f865c61155efc1f78170df25e3d7abec3cfae9fdd24e393d89f3170fbe022032cbdd8b8a09fb98f1ed4d9b8f2ffcb8563326ef839292b67c581f34a56f812a0121023498cfb68e409c99565689d76987ab5035e8498ef816a50ef2dbb37f585dd14effffffff563997398d371775f46301b9d21f950075211d249620156224303ad5a385d6e0010000006a473044022068b6d1783cd4f2a0910dd9bc25a762117b08132362fc9c5b1e0a1d3377b2daa4022038fabd7dc84c3a5f55dffd14d28fa34b8b93333761830104562bee60c3dafbba0121023498cfb68e409c99565689d76987ab5035e8498ef816a50ef2dbb37f585dd14effffffff0240a5e30e0000000017a914bcf184420cd4c06186b1766d9d0dba5cddb1ec8a8740e3f7020000000017a914bcf184420cd4c06186b1766d9d0dba5cddb1ec8a8700000000");
                done();
            });
        });

        it(' 4 to 4 sign BTc transaction', function (done) {
            var inputs = [input1, input2, input3, input4];
            var outputs = [output1, output2, output1, output2];
            request.params.input = inputs;
            request.params.output = outputs;

            conn.write(JSON.stringify(request));
            conn.on('data', function (data) {
                var retObj = JSON.parse(data.toString());
                // console.log(retObj);
                assert.equal(retObj.data.rawTx, "010000000411f9fc55b4fccd6d6f9f232d484eb9879c2435382cdc3c0330a038f09ce14694010000006a4730440220304084537143ac79bf1caeb9b447936a169a7b653a0a5b58ae267128e786b03802206d9fd0635b47a4fee9e9c8dfcc4a08d35daa8e596ee0002c224889eaf97537be0121023498cfb68e409c99565689d76987ab5035e8498ef816a50ef2dbb37f585dd14effffffff563997398d371775f46301b9d21f950075211d249620156224303ad5a385d6e0010000006b4830450221009abb3c2b60daa048eb1e55da7cf9d8f08f821500dcfdee326be971568deb0c1c02200d6c8e1674ec8a6b7ad5c04308c9492c0cb2669b816ea04189590e44f5e408390121023498cfb68e409c99565689d76987ab5035e8498ef816a50ef2dbb37f585dd14effffffff6700116ef595b8614dd6cfc26641a53a1f4677cd70e351c8c4c83c8b6b58207b000000006a47304402205dd40546d5890b9dbaba8528efaae30e724ccf6565e50fdbe9ef43a2394de86102206c8382c07044d5ce516f296318451bfe8e63bc3627eb9aef6e41f183325e976d012102a30204513b6b533358fbc58494116dead5e7e5f41d6f322dc14c57d35e64b5bdfffffffff5596fbbc02bedfed24c47729f10ae7d81c7a2b2b4c822c876f192b5055b73ff000000006b483045022100e22572a3c217b1349ec8e3ea3bce7aa821bd13bf416fc2097c7515603ac8319102200debb0a156997829f996b0fcb76d6c57ad0bdfa17856fe1fe5b0e7f3099270c9012102a30204513b6b533358fbc58494116dead5e7e5f41d6f322dc14c57d35e64b5bdffffffff0440a5e30e0000000017a914bcf184420cd4c06186b1766d9d0dba5cddb1ec8a8740e3f7020000000017a914bcf184420cd4c06186b1766d9d0dba5cddb1ec8a8740a5e30e0000000017a914bcf184420cd4c06186b1766d9d0dba5cddb1ec8a8740e3f7020000000017a914bcf184420cd4c06186b1766d9d0dba5cddb1ec8a8700000000");
                done();
            });
        });
    });

    describe('sign ETH transaction test', function () {
        var txData = {
            "from":"0x8C39e3540F626Ce753F2EAE0bBE643aB569b297a",
            "to":"0xea3300ca2e51b69026939b07fba329a639f50770",
            "value": "0x8AC7230489E80000",
            "nonce": "0x4",
            "gasPrice": "0x4a817c800",
            "gasLimit":"0x15f90",
            "data":"0xa9059cbb000000000000000000000000299432642dcc4c2f33ff0f5d41b8f4154b82ae2a00000000000000000000000000000000000000000000021e19e0c9bab2400000"
        };
        var request = 	{"version":"1.0", "method": "signTx", "params": {"symbol": "ETH", "privateKey":"de06e2f52440dd254c9b5fb00f036a434d447795912e2feaac8ef75f1a8884e9", "txData":txData}};

        it(' sign ETH transaction ...', function (done) {
            conn.write(JSON.stringify(request));
            conn.on('data', function (data) {
                var retObj = JSON.parse(data.toString());
                // console.log(retObj);
                assert.equal(retObj.data.rawTx, "0xf8b2048504a817c80083015f9094ea3300ca2e51b69026939b07fba329a639f50770888ac7230489e80000b844a9059cbb000000000000000000000000299432642dcc4c2f33ff0f5d41b8f4154b82ae2a00000000000000000000000000000000000000000000021e19e0c9bab24000001ca05202383ff8895d13ae009c8f5bfea3ebef5243bbdb652b4ddd1fba6c58257ed7a03f5ca72ff674f003e64ba904691cb5f7ccdba162f79f4bbf0d121b00330e44e1");
                done();
            });
        });
    });

    describe('sign LTC transaction test', function () {
        var input1 = {"txid":"b81517c0553d0aab41fd3ded54507506b12f5527698bb733aa373c1d1ef8e69a", "address":"LWuMbjp37id6YspS2RxAKW4QX4wVQ6R7nW",  "outputIndex": 0, "script":"76a914801d162ab176f7963fa46170417941f4d45c314788ac", "satoshis":10100000};
        var input2 = {"txid":"da3b5def91d7acf4d167d9291bf21437451eb3d9a8508f1ff6c215d63a326caa", "address":"LXaoPDpLNmG5ZG3YZn5asht6VLURFQKcRe",  "outputIndex": 1, "script":"76a9148792d528d23d80e41b61c95315d3d5d88dafedb488ac", "satoshis":10100000};
        var input3 = {"txid":"b81517c0553d0aab41fd3ded54507506b12f5527698bb733aa373c1d1ef8e69a", "address":"LXaoPDpLNmG5ZG3YZn5asht6VLURFQKcRe",  "outputIndex": 0, "script":"76a914801d162ab176f7963fa46170417941f4d45c314788ac", "satoshis":10100000};
        var input4 = {"txid":"b81517c0553d0aab41fd3ded54507506b12f5527698bb733aa373c1d1ef8e69a", "address":"LXaoPDpLNmG5ZG3YZn5asht6VLURFQKcRe",  "outputIndex": 3, "script":"76a914801d162ab176f7963fa46170417941f4d45c314788ac", "satoshis":10100000};

        var output1 = {"address":"LXaoPDpLNmG5ZG3YZn5asht6VLURFQKcRe", "satoshis":10000000};
        var output2 = {"address":"LWuMbjp37id6YspS2RxAKW4QX4wVQ6R7nW", "satoshis":800000};
        var output3 = {"address":"LXaoPDpLNmG5ZG3YZn5asht6VLURFQKcRe", "satoshis":3000000};
        var output4 = {"address":"LWuMbjp37id6YspS2RxAKW4QX4wVQ6R7nW", "satoshis":12000000};

        var privateKey1 = "T5s3b7H3GdDyUEFhG1nyRHqCUf7mNd9rwF1M8P26Qjd6RanZCzp1";
        var privateKey2 = "T7N2NvwixNsKc6VDtfdCt2fvEJoKZr1FDMvcyPcX7gdQc4H2iFT7";
        var privateKey3 = "T7N2NvwixNsKc6VDtfdCt2fvEJoKZr1FDMvcyPcX7gdQc4H2iFT7";
        var privateKey4 = "T5s3b7H3GdDyUEFhG1nyRHqCUf7mNd9rwF1M8P26Qjd6RanZCzp1";

        var inputs = [];
        var outputs = [];
        var privateKeys = [];
        var request = 	{"version":"1.0", "method": "signTx", "params": {"symbol": "LTC", "privateKey":privateKeys, "input":inputs, "output":outputs}};

        it(' 1 to 1 sign LTC transaction ', function (done) {
            var inputs = [input1];
            var outputs = [output1];
            var privateKeys = [privateKey1];
            request.params.input = inputs;
            request.params.output = outputs;
            request.params.privateKey = privateKeys;

            conn.write(JSON.stringify(request));
            conn.on('data', function (data) {
                var retObj = JSON.parse(data.toString());
                // console.log(retObj);
                assert.equal(retObj.data.rawTx, "01000000019ae6f81e1d3c37aa33b78b6927552fb106755054ed3dfd41ab0a3d55c01715b80000000000ffffffff0180969800000000001976a9148792d528d23d80e41b61c95315d3d5d88dafedb488ac00000000");
                done();
            });
        });

        it(' 1 to 2 sign LTC transaction ', function (done) {
            var inputs = [input1];
            var outputs = [output1, output2];
            var privateKeys = [privateKey1];
            request.params.input = inputs;
            request.params.output = outputs;
            request.params.privateKey = privateKeys;

            conn.write(JSON.stringify(request));
            conn.on('data', function (data) {
                var retObj = JSON.parse(data.toString());
                // console.log(retObj);
                assert.equal(retObj.data.rawTx, "01000000019ae6f81e1d3c37aa33b78b6927552fb106755054ed3dfd41ab0a3d55c01715b80000000000ffffffff0280969800000000001976a9148792d528d23d80e41b61c95315d3d5d88dafedb488ac00350c00000000001976a914801d162ab176f7963fa46170417941f4d45c314788ac00000000");
                done();
            });
        });

        it(' 2 to 1 sign LTC transaction ', function (done) {
            var inputs = [input1, input2];
            var outputs = [output1];
            var privateKeys = [privateKey1, privateKey2];
            request.params.input = inputs;
            request.params.output = outputs;
            request.params.privateKey = privateKeys;

            conn.write(JSON.stringify(request));
            conn.on('data', function (data) {
                var retObj = JSON.parse(data.toString());
                // console.log(retObj);
                assert.equal(retObj.data.rawTx, "01000000029ae6f81e1d3c37aa33b78b6927552fb106755054ed3dfd41ab0a3d55c01715b80000000000ffffffffaa6c323ad615c2f61f8f50a8d9b31e453714f21b29d967d1f4acd791ef5d3bda010000006b483045022100dc548c7655e663589451b8b9bca93714b6128a2f183b63ef013eac2ac1ba979802200ef2235658f71abb6ff76249c1fb4e108a524b26f1bf3a5d4519edd8eb280c61012103dc6d70f4f213c59dfb98b62cb63a9027b13524b84914ccd21112f88afa086471ffffffff0180969800000000001976a9148792d528d23d80e41b61c95315d3d5d88dafedb488ac00000000");
                done();
            });
        });

        it(' 2 to 2 sign LTC transaction ', function (done) {
            var inputs = [input1, input2];
            var outputs = [output1, output2];
            var privateKeys = [privateKey1, privateKey2];
            request.params.input = inputs;
            request.params.output = outputs;
            request.params.privateKey = privateKeys;

            conn.write(JSON.stringify(request));
            conn.on('data', function (data) {
                var retObj = JSON.parse(data.toString());
                // console.log(retObj);
                assert.equal(retObj.data.rawTx, "01000000029ae6f81e1d3c37aa33b78b6927552fb106755054ed3dfd41ab0a3d55c01715b80000000000ffffffffaa6c323ad615c2f61f8f50a8d9b31e453714f21b29d967d1f4acd791ef5d3bda010000006b483045022100ef6e7b2ebd749f4fa181e483b26fa3bddecf42e7f819ee7efbe3cc83a5b4abf0022060f307911b8e98018b7da9aa6bab5deca6f4dc57bfb1dd1ed73ed5c9bb57d974012103dc6d70f4f213c59dfb98b62cb63a9027b13524b84914ccd21112f88afa086471ffffffff0280969800000000001976a9148792d528d23d80e41b61c95315d3d5d88dafedb488ac00350c00000000001976a914801d162ab176f7963fa46170417941f4d45c314788ac00000000");
                done();
            });
        });

        it(' 4 to 4 sign LTC transaction ', function (done) {
            var inputs = [input1, input2, input3, input4];
            var outputs = [output1, output2, output3, output4];
            var privateKeys = [privateKey1, privateKey2, privateKey3, privateKey4];
            request.params.input = inputs;
            request.params.output = outputs;
            request.params.privateKey = privateKeys;

            conn.write(JSON.stringify(request));
            conn.on('data', function (data) {
                var retObj = JSON.parse(data.toString());
                // console.log(retObj);
                assert.equal(retObj.data.rawTx, "01000000049ae6f81e1d3c37aa33b78b6927552fb106755054ed3dfd41ab0a3d55c01715b80000000000ffffffffaa6c323ad615c2f61f8f50a8d9b31e453714f21b29d967d1f4acd791ef5d3bda010000006b483045022100fbf19a16dd896ae63a9d18f1011f16c80a970c910d316068be436cc58a2238d902200dbb91e07f1fee46c3725c95bb839a9619dc6651b944930bb8cc4fd1f1036fad012103dc6d70f4f213c59dfb98b62cb63a9027b13524b84914ccd21112f88afa086471ffffffff9ae6f81e1d3c37aa33b78b6927552fb106755054ed3dfd41ab0a3d55c01715b80000000000ffffffff9ae6f81e1d3c37aa33b78b6927552fb106755054ed3dfd41ab0a3d55c01715b80300000000ffffffff0480969800000000001976a9148792d528d23d80e41b61c95315d3d5d88dafedb488ac00350c00000000001976a914801d162ab176f7963fa46170417941f4d45c314788acc0c62d00000000001976a9148792d528d23d80e41b61c95315d3d5d88dafedb488ac001bb700000000001976a914801d162ab176f7963fa46170417941f4d45c314788ac00000000");
                done();
            });
        });
    });


    describe('sign and verify message test', function () {
        var privateKeyLTC = "T6T5FZuSh2YYSsShnCadEbBWT5pbYCT39EPD7wE6z97t6upq5iQw";
        var privateKeyBTC = "L4hArLJKVnJtX1NJpjC3yoNGwVFvw8y3es5Cy9b5Y4DoTy3FgJjW";
        var request = {"version":"1.0", "method": "signMsg", "params": {"symbol":"", "message": "This is an example of a signed message", "privateKey":""}};

        it(' sign LTC message ...', function (done) {
            request.params.symbol = "LTC";
            request.params.privateKey = privateKeyLTC;

            conn.write(JSON.stringify(request));
            conn.on('data', function (data) {
                var retObj = JSON.parse(data.toString());
                // console.log(retObj);
                assert.equal(retObj.state, 10000);
                done();
            });
        });

        it(' verify LTC message ...', function (done) {
            var verifyLTCTx = {"version":"1.0", "method": "verifyMsg", "params": {"symbol":"LTC", "message":"This is an example of a signed message",
                    "address": "LWuMbjp37id6YspS2RxAKW4QX4wVQ6R7nW", "signature":"H9DCctekNbmRQetnFG3aOtGLQFR9dz078JEuqZksMsUTPbGb/p9pIcKDfgx/D5LKfvsUsGgyz7Unyc7QIyqlBQw="}};

            conn.write(JSON.stringify(verifyLTCTx));
            conn.on('data', function (data) {
                var retObj = JSON.parse(data.toString());
                // console.log(retObj);
                assert.equal(retObj.state, 10000);
                done();
            });
        });

        it(' sign LTC empty message ...', function (done) {
            request.params.symbol = "LTC";
            request.params.message = "";
            request.params.privateKey = privateKeyLTC;

            conn.write(JSON.stringify(request));
            conn.on('data', function (data) {
                var retObj = JSON.parse(data.toString());
                // console.log(retObj);
                assert.equal(retObj.state, 10000);
                done();
            });
        });

        it(' verify LTC empty message ...', function (done) {
            var verifyLTCTx = {"version":"1.0", "method": "verifyMsg", "params": {"symbol":"LTC", "message":"",
                    "address": "LWuMbjp37id6YspS2RxAKW4QX4wVQ6R7nW", "signature":"H8qOB3I9FTwLspOx/qzqJPGu02alHeP7DkBjmRHJP6lcWFXezOW/MKannCEIExfhc/oBkgui5IhdWh5NZEz6JgU="}};

            conn.write(JSON.stringify(verifyLTCTx));
            conn.on('data', function (data) {
                var retObj = JSON.parse(data.toString());
                // console.log(retObj);
                assert.equal(retObj.state, 10000);
                done();
            });
        });

        it(' sign BTC message ...', function (done) {
            request.params.symbol = "BTC";
            request.params.privateKey = privateKeyBTC;

            conn.write(JSON.stringify(request));
            conn.on('data', function (data) {
                var retObj = JSON.parse(data.toString());
                // console.log(retObj);
                assert.equal(retObj.state, 10000);
                done();
            });
        });

        it(' verify BTC message ...', function (done) {
            var verifyBTCTx = {"version":"1.0", "method": "verifyMsg", "params": {"symbol":"BTC", "message":"This is an example of a signed message",
                    "address": "1EgHNyfE2Z1u3AqdSkNXnRgkgLxKDNSrMv", "signature":"H6FJxxtlyN/aC+NVTa2RTw0T7MShqjMA9NHYoLmpDV8PZJ06qhpMoHQor0QbC3iZ+aLTDWBpSF/49zQsz1UW1bM="}};

            conn.write(JSON.stringify(verifyBTCTx));
            conn.on('data', function (data) {
                var retObj = JSON.parse(data.toString());
                // console.log(retObj);
                assert.equal(retObj.state, 10000);
                done();
            });
        });

        it(' sign BTC empty message ...', function (done) {
            request.params.symbol = "BTC";
            request.params.message = "";
            request.params.privateKey = privateKeyBTC;

            conn.write(JSON.stringify(request));
            conn.on('data', function (data) {
                var retObj = JSON.parse(data.toString());
                // console.log(retObj);
                assert.equal(retObj.state, 10000);
                done();
            });
        });

        it(' verify BTC empty message ...', function (done) {
            var verifyBTCTx = {"version":"1.0", "method": "verifyMsg", "params": {"symbol":"BTC", "message":"",
                    "address": "1EgHNyfE2Z1u3AqdSkNXnRgkgLxKDNSrMv", "signature":"ILs5DKTIn2HAb0QWGvMuH6AmPw6rX2U+eWmBna0e0NUTZj1HjniyTSZrUo6hEDyeosjHa2yggPdOdRD14/bozrk="}};

            conn.write(JSON.stringify(verifyBTCTx));
            conn.on('data', function (data) {
                var retObj = JSON.parse(data.toString());
                // console.log(retObj);
                assert.equal(retObj.state, 10000);
                done();
            });
        });

    });

    describe(' verify address test', function () {
        var addressBTC = "1Cxhi4vEFd1DPUUmoy2BBkRofRpV76fNzf";
        var addressBTCT = "mzKezyiK9koQM6sS7KCVFSw6rhrYZNCVMm";
        var addressLTC = "LWuMbjp37id6YspS2RxAKW4QX4wVQ6R7nW";
        var addressETH = "0x8C39e3540F626Ce753F2EAE0bBE643aB569b297a";

        var request = {
            "version": "1.0",
            "method": "verifyAddress",
            "params": {"symbol": "BTC", "address": addressBTC}
        };

        it(' verify BTC address ...', function (done) {
            request.params.symbol = "BTC";
            request.params.address = addressBTC;

            conn.write(JSON.stringify(request));
            conn.on('data', function (data) {
                var retObj = JSON.parse(data.toString());
                // console.log(retObj);
                assert.equal(retObj.state, 10000);
                done();
            });
        });

        it(' verify BTC-T address ...', function (done) {
            request.params.symbol = "BTC-T";
            request.params.address = addressBTCT;

            conn.write(JSON.stringify(request));
            conn.on('data', function (data) {
                var retObj = JSON.parse(data.toString());
                // console.log(retObj);
                assert.equal(retObj.state, 10000);
                done();
            });
        });

        it(' verify LTC address ...', function (done) {
            request.params.symbol = "LTC";
            request.params.address = addressLTC;

            conn.write(JSON.stringify(request));
            conn.on('data', function (data) {
                var retObj = JSON.parse(data.toString());
                // console.log(retObj);
                assert.equal(retObj.state, 10000);
                done();
            });
        });

        it(' verify ETH address ...', function (done) {
            request.params.symbol = "ETH";
            request.params.address = addressETH;

            conn.write(JSON.stringify(request));
            conn.on('data', function (data) {
                var retObj = JSON.parse(data.toString());
                // console.log(retObj);
                assert.equal(retObj.state, 10000);
                done();
            });
        });

    });
});
